#!/bin/bash

# ip 集合
export IP="192.168.20.161 192.168.20.162 192.168.20.163 192.168.20.171 192.168.20.172 192.168.20.173"
# root 密码
export SSHPASS=Root@123!

for HOST in $IP; do
  ping -c 1 $HOST > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    echo "检测 $HOST 网络正常"
    sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $HOST
  else
    echo "检测 $HOST 网络连接异常"
  fi
done
